// 递归
function convert(arr, origin) {
    return arr.map((parent) => {
        let children = origin.filter((child) => parent.route_id === child.parent_id);
        if (children.length) {
            return { ...parent, children: convert(children, origin) };
        } else {
            return { ...parent };
        }
    });
}

let treeData = (state, getters) => {
    // 查找一级分类
    let cate_1st = state.routes.filter((item) => item.parent_id == 0);
    return treeData = [{
        route_id: "0",
        route_name: '全部分类',
        children: convert(cate_1st, state.routes),
    }]
}

let route_list = (state, getters) => {
    // 查找一级分类
    let cate_1st = state.routes.filter((item) => item.parent_id == 0);
    return convert(cate_1st, state.routes);
}

export default {
    treeData,
    route_list,
}